﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace msBsc.WebUi.wMall.Public
{
    public partial class wfTraveFoodList : msBsc.Cls.BPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindControls();
            }
        }
        private void BindControls()
        {
            if (!IsPostBack)
            {
            }
        }

        string countryId = "";
        string cityId = "";
        string destionId = "";
        private void getArea2(string parentsId)
        {
            using (msBsc.AppLogic.DataAlc.CBizCountryCity cbcc = new AppLogic.DataAlc.CBizCountryCity())
            {
                DataSet ds = cbcc.SelectCountryByParentId(parentsId);
                if (ds == null || ds.Tables[0].Rows.Count < 1)
                {
                    return;
                }
                cityId = this.GetParamHtValue("cityId");
                string ret = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 1000, "");
                if (string.IsNullOrEmpty(cityId))
                {
                    cityId = ds.Tables[0].Rows[0]["COUNTRY_CITY_ID"].ToString();
                }
                this.ExecJScript(@"updateSelet(""cityId_select""," + ret + @",""" + cityId + @""")");
                getArea3(cityId);
            }
        }
        private void getArea3(string parentsId)
        {
            using (msBsc.AppLogic.DataAlc.CBizCountryCity cbcc = new AppLogic.DataAlc.CBizCountryCity())
            {
                DataSet ds = cbcc.SelectCountryByParentId(parentsId);
                if (ds == null || ds.Tables[0].Rows.Count < 1)
                {
                    return;
                }
                string isAll = this.GetParamHtValue("isAll");
                if (isAll.ToLower() == "true")
                {
                    DataRow dr = ds.Tables[0].NewRow();
                    dr["COUNTRY_CITY_ID"] = "";
                    dr["COUNTRY_CITY_NME"] = "全部";
                    ds.Tables[0].Rows.InsertAt(dr, 0);
                }
                string ret = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 1000, "");
                destionId = this.GetParamHtValue("destionId");
                if (string.IsNullOrEmpty(destionId))
                {
                    destionId = ds.Tables[0].Rows[0]["COUNTRY_CITY_ID"].ToString();
                }
                this.ExecJScript(@"updateSelet(""destionId_select""," + ret + @",""" + destionId + @""")");

            }
        }
        private void initplace(string parentsId)
        {
            using (msBsc.AppLogic.DataAlc.CBizCountryCity cbcc = new AppLogic.DataAlc.CBizCountryCity())
            {
                DataSet ds = cbcc.SelectCountryByParentId(parentsId);
                if (ds == null || ds.Tables[0].Rows.Count < 1)
                {
                    return;
                }
                countryId = this.GetParamHtValue("countryId");
                if (string.IsNullOrEmpty(countryId))
                {
                    countryId = ds.Tables[0].Rows[0]["COUNTRY_CITY_ID"].ToString();
                }
                string ret = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 1000, "");
                this.ExecJScript(@"updateSelet(""countryId_select""," + ret + @",""" + countryId + @""")");
                getArea2(countryId);
            }
        }

        private void GetFoodList()
        {
            string pageRows = this.GetParamHtValue("pageRows");
            string pageNum = this.GetParamHtValue("pageNum");
            using (msBsc.AppLogic.DataAlc.CBizPushNiceFood niceFood = new AppLogic.DataAlc.CBizPushNiceFood())
            {
                int pRows = 15;
                int.TryParse(pageRows, out pRows);
                int pNum = 1;
                int.TryParse(pageNum, out pNum);
                DataSet ds = niceFood.GetNiceFoodForPageview(pRows, pNum, destionId, cityId, countryId);
                if (ds == null || ds.Tables[0].Rows.Count < 1)
                {
                    return;
                }
                string strJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", "", 1, 200, "");
              
                this.ExecJScript(@"laySvcList(" + strJson + "," + ds.Tables[0].Rows[0]["DATACOUNT"] + ")");
            }
        }

        public override void DoAction()
        {
            if (this.strAction == "init")
            {
                string parentsId = this.GetParamHtValue("parentsId");
                initplace(parentsId);
                GetFoodList();
                base.DoAction();
            }
        }
    }
}